# -*- coding: utf-8 -*-


blocksi_category = {}
#POTENTIALLY LIABLE
blocksi_category["1_1"] = "Potentially Liable, Drug Abuse"
blocksi_category["1_2"] = "Potentially Liable, Hacking" #da segnalare come pericolo???
blocksi_category["1_3"] = "Potentially Liable, Illegal or Unethical"
blocksi_category["1_4"] = "Potentially Liable, Discrimination"
blocksi_category["1_5"] = "Potentially Liable, Violence"
blocksi_category["1_6"] = "Potentially Liable, Proxy Avoidance"
blocksi_category["1_7"] = "Potentially Liable, Plagiarism"
blocksi_category["1_8"] = "Potentially Liable, Child Abuse"

#CONTROVERSIAL
blocksi_category["2_1"] = "Controversial, Alternative Beliefs"
blocksi_category["2_2"] = "Controversial, Abortion"
blocksi_category["2_3"] = "Controversial, Adult Materials"
blocksi_category["2_4"] = "Controversial, Advocacy Organizations"
blocksi_category["2_5"] = "Controversial, Gambling"
blocksi_category["2_6"] = "Controversial, Extremist Groups"
blocksi_category["2_7"] = "Controversial, Nudity and Risque"
blocksi_category["2_8"] = "Controversial, Pornography"
blocksi_category["2_9"] = "Controversial, Tasteless"
blocksi_category["2_10"] = "Controversial, Weapons"
blocksi_category["2_11"] = "Controversial, Homosexuality"
blocksi_category["2_12"] = "Controversial, Marijuana"
blocksi_category["2_13"] = "Controversial, Sex Education"
blocksi_category["2_14"] = "Controversial, Alcohol"
blocksi_category["2_15"] = "Controversial, Tobacco"
blocksi_category["2_16"] = "Controversial, Lingerie and Swimsuit"
blocksi_category["2_17"] = "Controversial, Sports Hunting and War Games"
    
#BANDWIDTH CONSUMING
blocksi_category["3_1"] = "Bandwidth Consuming, Freware and Software Downloads"
blocksi_category["3_2"] = "Bandwidth Consuming, File Sharing and Storage" 
blocksi_category["3_3"] = "Bandwidth Consuming, Streaming Media and Download"
blocksi_category["3_4"] = "Bandwidth Consuming, Peer-to-peer File Sharing"
blocksi_category["3_5"] = "Bandwidth Consuming, Internet Radio and TV"
blocksi_category["3_6"] = "Bandwidth Consuming, Internet Telephony"
    
#SECURITY RISK
blocksi_category["4_1"] = "Security Risk, Malicious Websites" #da segnalare come pericolo!!!
blocksi_category["4_2"] = "Security Risk, Phishing" #da segnalare come pericolo!!!
blocksi_category["4_3"] = "Security Risk, Spam URLs" #da segnalare come pericolo!!!

#GENERAL INTEREST, BUSINESS
blocksi_category["5_1"] = "General Interest, Business, Finance and Banking"
blocksi_category["5_2"] = "General Interest, Business, Search Engines and Portals"
blocksi_category["5_3"] = "General Interest, Business, General Organizations"   
blocksi_category["5_4"] = "General Interest, Business"    
blocksi_category["5_5"] = "General Interest, Business, Information Technology" 
blocksi_category["5_6"] = "General Interest, Business, Government and Legal Organizations"    
blocksi_category["5_7"] = "General Interest, Business, Armed Forces"    
blocksi_category["5_8"] = "General Interest, Business, Web Hosting"
blocksi_category["5_9"] = "General Interest, Business, Secure Websites"
blocksi_category["5_10"] = "General Interest, Business, Web-based Applications"    

#GENERAL INTEREST, PERSONAL
blocksi_category["6_1"] = "General Interest, Personal, Advertising"
blocksi_category["6_2"] = "General Interest, Personal, Brokerage and Trading"
blocksi_category["6_3"] = "General Interest, Personal, Games"   
blocksi_category["6_4"] = "General Interest, Personal, Web-based Email"    
blocksi_category["6_5"] = "General Interest, Personal, Entertainment" 
blocksi_category["6_6"] = "General Interest, Personal, Arts and Culture"    
blocksi_category["6_7"] = "General Interest, Personal, Education"    
blocksi_category["6_8"] = "General Interest, Personal, Health and Wellness"
blocksi_category["6_9"] = "General Interest, Personal, Job Search"
blocksi_category["6_10"] = "General Interest, Personal, Medicine"    
blocksi_category["6_11"] = "General Interest, Personal, News and Media"
blocksi_category["6_12"] = "General Interest, Personal, Social Networking"
blocksi_category["6_13"] = "General Interest, Personal, Political Organizations"
blocksi_category["6_14"] = "General Interest, Personal, Reference"
blocksi_category["6_15"] = "General Interest, Personal, Global Religion"
blocksi_category["6_16"] = "General Interest, Personal, Shopping and Auction"
blocksi_category["6_17"] = "General Interest, Personal, Society and Lifestyles"
blocksi_category["6_18"] = "General Interest, Personal, Sports Travel"
blocksi_category["6_19"] = "General Interest, Personal, Personal Vehicles"
blocksi_category["6_20"] = "General Interest, Personal, Dynamic Content"
blocksi_category["6_21"] = "General Interest, Personal, Miscellaneous"
blocksi_category["6_22"] = "General Interest, Personal, Folklore"
blocksi_category["6_23"] = "General Interest, Personal, Web Chat"
blocksi_category["6_24"] = "General Interest, Personal, Instant Messaging"
blocksi_category["6_25"] = "General Interest, Personal, Newsgroups and Message Boards"
blocksi_category["6_26"] = "General Interest, Personal, Digital Postcards"
blocksi_category["6_27"] = "General Interest, Personal, Child Education"
blocksi_category["6_28"] = "General Interest, Personal, Real Estate"
blocksi_category["6_29"] = "General Interest, Personal, Restaurant and Dining"
blocksi_category["6_30"] = "General Interest, Personal, Personal Websites and Blogs"
blocksi_category["6_31"] = "General Interest, Personal, Content Servers"
blocksi_category["6_32"] = "General Interest, Personal, Domain Parking"
blocksi_category["6_33"] = "General Interest, Personal, Personal Privacy"

#UNRATED
blocksi_category["7_0"] = "Unrated"


import os
import string
import sys

response_name = "responseblocksi"

def ask_to_blocksi(domain):
    request = "wget -q -Y on \"service.block.si:3000/getRating?url='"+domain+"'\" -O "+response_name
    os.system(request)

#print sys.argv[1] #stampa di test
ask_to_blocksi(sys.argv[1])
f = open(response_name)
while True:                 #togliere il while, perchè è una sola riga
    line = f.readline()
    if not line: break
    #print line #stampa di test
    lista = string.split(line,":")
    n_elem = 1
    for elem in lista:
        if n_elem == 3:
            elem = elem[:-1] #tolgo } o \n
            #print sys.argv[1], elem #stampa di test
            if elem == "null":
                print sys.argv[1], "Unrated"
            elif elem == "\"-2\"":
                print sys.argv[1], "status false"
            elif elem == "\"error\"":
                print sys.argv[1], "error"
            elif elem == "":
                print sys.argv[1], line #fino ad adesso mai verificato: si dovrebbe verificare quando: come www.juve.it, vedi domande
            else:
                print sys.argv[1], blocksi_category[elem[1:-1]] #tolgo " e "
        n_elem += 1

#cancellare il file delle risposta
os.remove(response_name)
